
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>文章操作</title>
    <{include file="article/public/header"}>
    <link rel="stylesheet" href="/static/adminlte/plugins/summernote/summernote-bs4.min.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="/static/adminlte/plugins/icheck-bootstrap/icheck-bootstrap.min.css">

</head>
<body class="hold-transition sidebar-mini layout-fixed">
<!-- Site wrapper -->
<div class="wrapper">
    <!-- Navbar -->
    <{include file="article/public/navbar"}>
    <!-- /.navbar -->

    <!-- Main Sidebar Container -->
    <!--左侧菜单-->
    <{include file="article/public/sidebar"}>

    <div class="content-wrapper">
        <!-- 面包屑导航 -->
        <section class="content-header">

        </section>

        <!-- 内容区-->
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <!-- left column -->
                    <div class="col-md-12">
                        <div class="card card-danger">
                            <div class="card-header">
                                <h3 class="card-title ">坚持原创，从我做起！</h3>
                            </div>

                            <form method="post" action="<{:url('article_action')}>" id="check-form">
                                <div class="card-body">
                                    <div class="form-group">
                                        <label for="author">作者</label>
                                        <input autocomplete="on" name="author" value="<{:isset($data.author)?$data.author:''}>" type="text" class="form-control" id="author" placeholder="发布者">
                                        <span class="bs-red">网名、昵称等</span>
                                    </div>
                                    <div class="form-group">
                                        <label for="category_id">文章分类</label>
                                        <select name="category_id" id="category_id" class="form-control">

                                            <{if !empty($category)}>
                                            <{foreach $category as $one}>
                                            <option  <{if !empty($data['category_id'])&&$data['category_id']==$one.id}>selected<{/if}> value="<{$one.id}>"><{$one.name}></option>

                                            <{if !empty($one.subcat)}>
                                             <{foreach $one.subcat as $two}>
                                             <option   <{if !empty($data['category_id'])&&$data['category_id']==$two.id}>selected<{/if}>   value ="<{$two.id}>" >|____<{$two.name}></option>
                                             <{/foreach}>
                                            <{/if}>

                                            <{/foreach}>
                                            <{else}>
                                            <option   value="0">请先配置分类</option>
                                            <{/if}>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <label for="title">标题</label>
                                        <input name="title" value="<{$data?$data.title:''}>" type="text" class="form-control" id="title" placeholder="请输入标题">
                                        <input type="hidden" name="id" value="<{$data?$data.id:'0'}>">
                                    </div>

                                    <div class="form-group">
                                        <label for="price">价格</label>
                                        <input name="price" value="<{:isset($data.price)?$data.price:'0.01'}>" min="0" type="number" class="form-control" id="price" placeholder="阅读全文价格">
                                       <span class="bs-red">需要支付x元后可以阅读全文</span>
                                    </div>

                                    <!--<div class="form-group">
                                        <label for="free_percent">试读比例</label>
                                        <input name="free_percent" value="<{:isset($data.free_percent)?$data.free_percent:'10'}>" min="0" type="number" step="1" class="form-control" id="free_percent" >
                                        <span class="bs-red">可以免费阅读的比例0~100，按字符长度统计。</span>
                                    </div>-->


                                    <div class="form-group">
                                        <label for="status">是否发布</label>
                                        <div class="form-group clearfix">
                                            <div class="icheck-success d-block ">
                                                <input type="checkbox" name="status" id="status" <{if !empty($data.status)}>checked<{/if}>  >
                                                <label for="status">
                                                    启用
                                                </label>
                                            </div>
                                            <span class="bs-red">发布后用户可以阅读和购买。</span>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="desc">摘要/简介</label>
                                        <textarea id="desc" maxlength="200" name="desc" class="form-control"  ><{:isset($data.desc)?$data.desc:''}></textarea>
                                        <span class="bs-red">文章的核心提炼(200字以内)，文章的点睛简述，吸引用户“阅读全文“的关键提炼，注意要和文章内容相关性一致，否则将会被下线或者封号。不填写时默认抓取文章内容的前100字。</span>
                                    </div>
                                    <div class="form-group">
                                        <label for="textarea">内容</label>
                                        <textarea id="textarea" name="content" class="form-control"  ><{$data?$data.content:''}></textarea>
                                    </div>

                                </div>


                                <div class="card-footer">
                                    <button type="button" onclick="form_submit()" class="btn btn-primary">提交保存</button>
                                    <a  href="<{:url('index')}>" class="btn btn-default bs-left-30">返回列表</a>
                                </div>
                            </form>
                        </div>

                    </div>

                </div>

            </div>
        </section>
    </div>



</div>
<!-- ./wrapper -->

<{include file="article/public/footer"}>

<script src="/static/adminlte/plugins/summernote/summernote-bs4.min.js"></script>

<script>

    //上传图片
    function uploadFile($summernote, file) {
        var data = new FormData();
        data.append('fileKey','bs_shop')
        data.append('from','plugin_article')
        data.append("bs_shop", file);
        $.ajax({
            url:"<{:url('/admin/upload/image')}>",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function (res) {
                res = JSON.parse(res)
                if (res.code==0){

                    $summernote.summernote('insertImage', res.data.url, function ($image) {
                        $image.attr('src', res.data.url);
                    });
                    //$summernote.summernote('insertImage', res.data.url,'img');
                }

            }
        });
    }
    //删除图片
    function removeFile(target){
        var imgsrc = target[0].currentSrc;
        console.log(imgsrc)
        $.post('page/remove_img.php',{
            imgSrc:imgsrc
        },function(data){
            console.log(data);
        })

    }
    $(document).ready(function () {
        var $summernote = $('#textarea').summernote({
            height:300,                 // set editor height
            minHeight:null,             // set minimum height of editor
            maxHeight:null,             // set maximum height of editor
            focus:true      ,            //
            callbacks: {
                //上传时调用
                onImageUpload: function (files) {
                    uploadFile($summernote, files[0]);
                },
                //删除时调用
                onMediaDelete: function (target) {
                    removeFile(target);
                }
            }

        });

    })

</script>

</body>
</html>
